package 剑指Offer;

class ListNode {
    int val;
    ListNode next;

    ListNode(int x) {
        val = x;
    }
}

public class Offer18_删除链表的节点 {
    public ListNode deleteNode(ListNode head, int val) {
        //base case
        if (head.val == val) {
            return head.next;
        }
        ListNode slow = head;
        ListNode fast = head.next;
        while (slow != null && fast.val != val) {
            slow = slow.next;
            fast = fast.next;
        }
        //fast到达了目标值
        slow.next = fast.next;
        return head;
    }
}
